import time
from selenium.webdriver.common.by import By
from A3mall.Page.Page import Page


class Page2(Page):
    # 断言2：文本断言：欢迎回来
    dy2_loc=(By.PARTIAL_LINK_TEXT,'欢迎回来，130')
    def dy2(self):
        return self.text(self.dy2_loc)

    #点击首页
    home_loc=(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a')
    def home(self):
        self.click(self.home_loc)

    #搜索框输入：非洲之心 并 回车
    search_loc=(By.CLASS_NAME,'search-input')
    def search(self):
        self.send_keys(self.search_loc,'非洲之心')
        self.enter(self.search_loc)

    #选择商品：非洲之心
    goods_loc=(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/span/a/img')
    def goods(self):
        self.click(self.goods_loc)

    #商品数量输入：2
    num_loc=(By.ID,'store_nums')
    def num(self):
        self.clear(self.num_loc)
        time.sleep(2)
        self.send_keys(self.num_loc,'2')
    #点击立即购买
    buy_loc=(By.XPATH,'//a[@id="buy-cart"]')
    def buy(self):
        self.click(self.buy_loc)
    #选择收货地址
    addr_loc=(By.XPATH,'//input[@id="address-36" and @name="address_id"]')
    def addr(self):
        self.click(self.addr_loc)
    #选择支付方式
    money_loc=(By.XPATH,'//*[@id="theForm"]/div[3]/div[2]/div[1]/label/input')
    def money(self):
        self.click(self.money_loc)
    #点击下一步
    next_loc=(By.ID,'order-button')
    def next(self):
        self.click(self.next_loc)
    #断言3： 文本断言：订单支付成功
    dy3_loc=(By.XPATH,'/html/body/div[4]/div[3]/span')
    def dy3(self):
        return self.text(self.dy3_loc)

    # 调用操作和页面元素
    def luoji_a3mall_02_search(self):
        self.luoji_a3mall_01_login()
        time.sleep(3)
        assert '欢迎回来，13051749131' == self.dy2()
        print('断言2：文本断言：欢迎回来，13051749131：',self.dy2())
        self.home()
        self.search()
        self.goods()
        self.num()
        self.buy()
        self.addr()
        self.money()
        self.next()
        time.sleep(3)
        assert '您的订单支付成功' == self.dy3()
        print('断言3：文本断言：您的订单支付成功：',self.dy3())

